package com.wyw.minio.learning.utils;

import cn.hutool.json.JSONUtil;
import com.wyw.minio.learning.config.MinioProperties;
import io.minio.admin.MinioAdminClient;
import org.springframework.stereotype.Component;

/**
 * @Title
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2024/3/28 16:52
 * Update History:
 * Author        Time            Content
 */
@Component
public class MinioAdminUtils {

    private MinioAdminClient minioAdminClient;

    private final MinioProperties minioProperties;

    public MinioAdminUtils(MinioAdminClient minioAdminClient, MinioProperties minioProperties) {
        this.minioAdminClient = minioAdminClient;
        this.minioProperties = minioProperties;
    }

    /**
     * 下面的逻辑自行封装 使用minioAdminClient + . 的方式可以查看对应的方法，按需进行封装
     */
    public String listUsers() {
        try {
            return JSONUtil.parse(minioAdminClient.listUsers()).toStringPretty();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
